<template>
  <div>
      <h3 style="text-align:center">登录</h3>
    <van-form @submit.native.prevent>
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" @click="btn"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  // 组件名称
  name: "demo",
  // 组件参数 接收来自父组件的数据
  props: [],
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {
        url:"",
      username: "",
      password: "",
    };
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
    btn() {
      if (this.username == "" || this.password == "") {
        return false;
      }
      let formdata = new FormData();
      formdata.append("mobile", this.username);
      formdata.append("pwd", this.password);

      this.$axios
        .post(`${this.url}/user/m/login?deviceId=007&deviceName=monkey`, formdata)
        .then((res) => {
            console.log(res)
            this.$store.commit("adduser",res.data)
            this.$router.go(-1)
        })
    },
  },
  //生命周期
  created() {},
  mounted() {
    this.url = this.$store.state.appurl;
  },
};
</script> 

<style scoped>
</style>
